/*
 * Filename: g:\espidf_workspace\idf_S3_T-Watch\main\network\http.h
 * Path: g:\espidf_workspace\idf_S3_T-Watch\main\network
 * Created Date: Friday, June 20th 2025, 11:25:14 am
 * Author: sss
 * 
 * Copyright (c) 2025 Your Company
 */
/**
HTTPClient& http = HTTPClient::get_instance();
http.get("http://www.baidu.com",_http_event_handler);
esp_err_t _http_event_handler(esp_http_client_event_t *evt)
{
    static char *output_buffer;  // Buffer to store response of http request from event handler
    static int output_len;       // Stores number of bytes read
    switch(evt->event_id) {
        case HTTP_EVENT_ERROR:
            ESP_LOGI(TAG, "HTTP_EVENT_ERROR");
            break;
        case HTTP_EVENT_ON_CONNECTED:
            ESP_LOGI(TAG, "HTTP_EVENT_ON_CONNECTED");
            break;
        case HTTP_EVENT_HEADER_SENT:
            ESP_LOGI(TAG, "HTTP_EVENT_HEADER_SENT");
            break;
        case HTTP_EVENT_ON_HEADER:
            ESP_LOGI(TAG, "HTTP_EVENT_ON_HEADER, key=%s, value=%s", evt->header_key, evt->header_value);
            break;
        case HTTP_EVENT_ON_DATA:
            // ESP_LOGI(TAG, "HTTP_EVENT_ON_DATA, len=%d", evt->data_len);
            // Clean the buffer in case of a new request
            // printf(evt->data);
            // ESP_LOGI(TAG, "%s" , (char*)evt->data);

            break;
        case HTTP_EVENT_ON_FINISH:
            ESP_LOGI(TAG, "HTTP_EVENT_ON_FINISH");
            
            break;
        case HTTP_EVENT_DISCONNECTED:
            ESP_LOGI(TAG, "HTTP_EVENT_DISCONNECTED");
            break;
        case HTTP_EVENT_REDIRECT:
            ESP_LOGI(TAG, "HTTP_EVENT_REDIRECT");
            break;
    }
    return ESP_OK;
}
*/


#pragma once
#include "esp_http_client.h"

#define MAX_HTTP_RECV_BUFFER 512
#define MAX_HTTP_OUTPUT_BUFFER 2048

class HTTPClient {
private:
    HTTPClient();
    ~HTTPClient();
    char local_response_buffer[MAX_HTTP_OUTPUT_BUFFER + 1] = {0};
    esp_http_client_handle_t client;

public:
    static HTTPClient& get_instance(){
        static HTTPClient client;
        return client;
    };

    HTTPClient(const HTTPClient&) = delete;
    void operator=(const HTTPClient&) = delete;

    void get(const char* url, http_event_handle_cb _handle_cb);
    void post(const char* url, const char* post_data, http_event_handle_cb _handle_cb);

};